<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class ModelCT extends Controller
{
    public function test()
    {
        $res = DB::table('user')->skip(10)->take(10)->get();
        return view('test/modeltest')->with('info',$res);
    }
    public function page_next(Request $request,$page=1)
    {
        // 规定每页显示条数
        $page +=1;
        $num = 10;
        //计算总页数
        $user_info_num= DB::table('user')->count();
        //上舍入取整,计算总页数
        $total_page = intval(ceil($user_info_num/10));
        if ($page >$total_page){
            $page = $total_page;
        }
        // 计算偏移量
        $nu = ($page-1)*$num;
        $res = DB::table('user')->skip($nu)->take($num)->get();
        $data = [$res,$page];
        return view('test/modeltest')->with('info',$data);

    }

    public function page_before(Request $request,$page)
    {
        // 规定每页显示条数
        $page -=1;
        if ($page <= 0){
            $page =1;
        }
        $num = 10;
        //计算总页数
        $user_info_num= DB::table('user')->count();
        //上舍入取整,计算总页数
        $total_page = intval(ceil($user_info_num/10));
        // 计算偏移量
        $nu = ($page-1)*$num;
        $res = DB::table('user')->skip($nu)->take($num)->get();
        $data = [$res,$page];
        return view('test/modeltest')->with('info',$data);

    }

    public function del(Request $request)
    {
        $data = $request->all();
        $res = DB::table('user')->whereIn('id',$data['keys'])->delete();
        if ($res){
            return array('code'=>1,'info'=>'ok');
        }else{
            return array('code'=>0,'info'=>'');
        }





    }
}
